package com.ajie.controller;

import com.ajie.entity.Moment;
import com.ajie.service.MomentService;
import com.ajie.utils.DateUtils;
import com.ajie.utils.QueryInfo;
import com.ajie.utils.Result;
import com.ajie.utils.SecurityUtil;
import com.ajie.vo.MomentVo;
import com.ajie.vo.QuestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 动态数据数据控制层
 */
@RestController
@Api(tags = "动态数据")
@RequestMapping("/moments")
@Slf4j
public class MomentController {
    
    @Autowired
    private MomentService momentService;
    
    @Autowired
    private HttpServletRequest request;
    
    @Value("${jwt.tokenHeader}")
    private String tokenHeader;
    
    @ApiOperation(value = "分页查询")
    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryInfo queryInfo){
        log.info("该文件名是：MomentController,该方法是：findPage");
        String header = request.getHeader(tokenHeader);
        return momentService.findPage(queryInfo,header);
    }
    
    @ApiOperation(value = "分页查询")
    @PostMapping("/findPageCheck")
    public Result findPageCheck(@RequestBody QueryInfo queryInfo){
        log.info("该文件名是：MomentController,该方法是：findPage");
        String header = request.getHeader(tokenHeader);
        return momentService.findPageCheck(queryInfo,header);
    }
    
    @ApiOperation(value = "添加动态数据")
    @PostMapping("/insert")
    public Result insert(@RequestBody Moment moment){
        log.info("该文件名是：MomentController,该方法是：insert");
        moment.setUserId(SecurityUtil.getUserId());
        moment.setCreateTime(DateUtils.getDateTime());
        return momentService.insert(moment);
    }
    
    @ApiOperation(value = "添加动态数据")
    @PostMapping("/insertQuest")
    public Result insertQuest(@RequestBody QuestVo questVo){
        log.info("该文件名是：MomentController,该方法是：insert");
        log.info("questVo=>{}",questVo);
        return momentService.insertQuest(questVo);
    }
    
    @ApiOperation(value = "删除动态数据")
    @DeleteMapping("/delete/{id}")
    public Result delete( @PathVariable("id") Long id){
        log.info("该文件名是：MomentController,该方法是：delete");
        return momentService.delete(id);
    }
    
    @ApiOperation(value = "修改动态数据")
    @PutMapping("/update")
    public Result update(@RequestBody Moment moment){
        log.info("该文件名是：MomentController,该方法是：update");
        return momentService.update(moment);
    }
    
    @ApiOperation(value = "修改动态数据")
    @PutMapping("/getAllMomentList")
    public List<MomentVo> getAllMomentList() {
        List<MomentVo> momentList = momentService.getAll();
        log.info("动态3",momentList);
        return momentList;
    }
    
    @ApiOperation(value = "通过专家id分页查询")
    @PostMapping("/findPageByCreatedId")
    public Result findPageByCreatedId(@RequestBody QueryInfo queryInfo){
        log.info("该文件名是：MomentController,该方法是：findPage");
        String header = request.getHeader(tokenHeader);
        return momentService.findPageByCreatedId(queryInfo,header);
    }
    
    @ApiOperation(value = "修改新闻咨询")
    @PutMapping("/updateStatus/{id}")
    public Result updateStatus(@PathVariable("id") Long id){
        log.info("该文件名是：NewController,该方法是：update");
        return momentService.updateStatus(id);
    }
    
}
